#include <iostream>
#include <list>
#include <string.h>
using namespace std;

// 反转链表
void printVec(int vec[], int m)
{
    for (int i = 0; i < m; i++)
    {
        cout << vec[i] << "-";
    }
    cout << endl;
}

struct ListNode
{
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL)
    {
    }
};
void printNode(ListNode* node)
{
    for (; node != NULL; )
    {
        cout << node->val << "---";
        node = node->next;
    }
    cout << endl;
}
class Solution
{
public:
    ListNode *ReverseList(ListNode *pHead)
    {
        ListNode *end = NULL;
        for (; pHead != NULL;)
        {
            ListNode *tmp = pHead->next;
            pHead->next = end;
            end = pHead;
            pHead = tmp;
        }
        return end;
    }
    
};

int main()
{
    Solution s;
    ListNode* root = new ListNode(0);
    root->next = new ListNode(1);
    root->next->next = new ListNode(2);

    root->next->next->next = new ListNode(3);
    root->next->next->next->next = new ListNode(4);

    printNode(root);
    root = s.ReverseList(root);
    printNode(root);
    return 0;
}